/**
* Copyright 2013 nabla
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*
*/
package com.nabla.wapp.report.shared.parameter;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.Set;


public class ParameterGroup extends LinkedList<IParameter> implements IParameter {

	private static final long serialVersionUID = 1L;

	private String		name;
	private String		prompt;

	public ParameterGroup() {}	// for serialization only

	public ParameterGroup(final String name, final String prompt) {
		this.name = name;
		this.prompt = prompt;
	}

	public boolean getCascading() {
		return false;
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public String getPrompt() {
		return prompt;
	}

	@Override
	public void setPrompt(String prompt) {
		this.prompt = prompt;
	}

	@Override
	public void addNameToSet(final Set<String> names) {
		for (IParameter p : this)
			p.addNameToSet(names);
	}

	@Override
	public RemoveParameterStatus removeParameter(final Set<String> names) {
		RemoveParameterStatus status = RemoveParameterStatus.NOP;
		final Iterator<IParameter> iter = this.iterator();
		while (iter.hasNext()) {
			switch (iter.next().removeParameter(names)) {
			case SUCCESS:
				iter.remove();
				status = isEmpty() ? RemoveParameterStatus.SUCCESS : RemoveParameterStatus.SUCCESS_NOT_EMPTY;
				break;
			case SUCCESS_NOT_EMPTY:
				status = RemoveParameterStatus.SUCCESS_NOT_EMPTY;
				break;
			default:
			case NOP:
				break;
			}
		}
		return status;
	}
}
